package com.bins.dentist.clinic.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bins.dentist.clinic.model.dto.RoleDto;
import com.bins.dentist.clinic.model.dto.RolePageDto;
import com.bins.dentist.clinic.model.dto.RolePermDto;
import com.bins.dentist.clinic.model.vo.*;
import com.bins.dentist.clinic.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bins
 * @since 2023-02-20 20:53:31
 */
@RestController
@RequestMapping("/system/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @GetMapping("/page")
    public ResultVo<IPage<RoleVo>> pageList(RolePageDto pageDto) {
        return ResultVo.ok().data(roleService.getPage(pageDto));
    }

    @GetMapping("/detail")
    public ResultVo<RoleVo> detail(RoleDto dto) {
        return ResultVo.ok().data(roleService.getDetailById(dto));
    }

    @PostMapping("/save")
    public ResultVo<RoleVo> saveRole(@RequestBody RoleDto dto) {
        return ResultVo.ok().data(roleService.saveRole(dto));
    }

    @PostMapping("/delete")
    public ResultVo<Integer> deleteRole(@RequestBody RoleDto dto){
        return ResultVo.ok().data(roleService.deleteRole(dto)) ;
    }

    @GetMapping("/select")
    public ResultVo<List<SimpleSelectVo>> roleSelect(RoleDto dto) {
        return ResultVo.ok().data(roleService.roleSelect(dto));
    }

    @GetMapping("/rolePermInfo")
    public ResultVo<RolePermInfoVo> rolePermInfo(RoleDto dto) {
        return ResultVo.ok().data(roleService.rolePermInfo(dto));
    }

    @GetMapping("/rolePermList")
    public ResultVo<List<RolePermVo>> rolePermList(RoleDto dto) {
        return ResultVo.ok().data(roleService.rolePermList(dto));
    }

    @PostMapping("/saveRolePerm")
    public ResultVo<RoleVo> saveRolePerm(@RequestBody RolePermDto dto) {
        return ResultVo.ok().data(roleService.saveRolePerm(dto));
    }
}

